<?php
namespace App\Http\Controllers\Admin;

use App\Services\Admin\UserService;
use Illuminate\Http\Request;

class UserController extends BaseController
{
    public function __construct(UserService $userService)
    {
        $this->db = $userService;
    }

    /**
     * 列表
     */
    public function getIndex(Request $request)
    {
//        header('Access-Control-Allow-Origin: *');
//        $headers = $this->getAid($request);
//        if ($headers['code'] != 0) {
//            return $this->toJson(-2, $headers['msg']);
//        }
        $pages['start'] = $request->get('pageStart', 0);
        $pages['limit'] = $request->get('pageLimit', 10);
        $res = $this->db->getIndex($pages);
        if ($res['code']!=0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    /**
     * 游客列表
     */
    public function getVisitorIndex(Request $request)
    {
//        header('Access-Control-Allow-Origin: *');
//        $headers = $this->getAid($request);
//        if ($headers['code'] != 0) {
//            return $this->toJson(-2, $headers['msg']);
//        }
        $pages['start'] = $request->get('pageStart', 0);
        $pages['limit'] = $request->get('pageLimit', 10);
        $rst = $this->db->getVisitorIndex($pages);
        if ($rst['code']!=0) {
            return $this->toJson(-2, $rst['msg']);
        }
        return $this->toJson(0, '', $rst['data']);
    }
}